import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4

Item {

    id: root
    Component.onCompleted: {
        root.addCol('handle1', 't1')
        root.addCol('handle2', 't2')
        root.addRowData({ handle1: '1', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
        root.addRowData({ handle1: '2', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
        root.addRowData({ handle1: '3', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
        root.addRowData({ handle1: '4', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
        root.addRowData({ handle1: '5', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
        root.addRowData({ handle1: '6', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
        root.addRowData({ handle1: '7', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
        root.addRowData({ handle1: '8', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
        root.addRowData({ handle1: '9', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
    }
    function addCol(rolorstr, titlestr)
    {
        var prefix = 'import QtQuick 2.7;import QtQuick.Controls 1.4;TableViewColumn { width: tableView.viewport.width/tableView.columnCount;';
        var str = prefix +"role: \"" + rolorstr + "\";title: \"" + titlestr + "\" } ";
        tableView.addColumn(Qt.createQmlObject(str, tableView, "main.qml"));
    }
    function addRowData(d)
    {
        tablemode.append(d);
    }
    ListModel {
        id: tablemode
        // ListElement {
        //     columnHandle1: "1"
        //     columnHandle2: "2"
        // }
    }
    TableView {
        id: tableView
        anchors.fill: parent
        alternatingRowColors: false
        selectionMode: SelectionMode.MultiSelection
        TableViewColumn {
            role: "columnHandle1"
            title: "标题1"
            width: tableView.viewport.width/tableView.columnCount
        }
        TableViewColumn {
            role: "columnHandle2"
            title: "标题2"
            width: tableView.viewport.width/tableView.columnCount
        }
        model: tablemode
        headerDelegate: Rectangle {
        width: 100
        height: 40
        border.color: "black"
        //border.width: 1
        //radius: 5
        gradient: Gradient {
        GradientStop {
            position: 0.0; color: "#085FB2"
        }
        GradientStop {
            position: 1.0; color: "#00498C"
        }
    }
    Text {
        id: rawtxt
        anchors.centerIn: parent
        text: styleData.value
        font.pixelSize: parent.height*0.5
    }
}
rowDelegate: Rectangle {
height: 50
color: "#052641"
anchors.leftMargin: 2
}
itemDelegate: Rectangle {
//color: "#052641"
property int selectSig: styleData.selected ? 1: 0
onSelectSigChanged: {
    // console.log('sig', selectSig)
    // if (1 === selectSig){
    //     console.log('sig', selectSig, ' value: ', styleData.value, ' row: ', styleData.row, ' curRow: ', tableView.currentRow,
    //                 ' pressed: ', styleData.pressed)
    //     if (styleData.pressed){
    //         root.addRowData({ handle1: '3', handle2: '2', columnHandle1: '3', columnHandle2: '4' })
    // }
    // }
}
border.width: 1
color: styleData.selected ? "#dd00498C": "#052641"
Text {
    id: rawtxt
    anchors.verticalCenter: parent.verticalCenter
    //anchors.fill: parent
    anchors.leftMargin: 5
    color: styleData.selected ? "#00CCFE": "white"
    text: styleData.selected ? '选我': styleData.value
    font.pixelSize: parent.height*0.4
}
}
// style: TableViewStyle {
//     textColor: "white"
//     highlightedTextColor: "#00CCFE"
//     backgroundColor: "#052641"
// }
}
}
